package com.haidechizi.i18n.code.generator.common.message.key;

import com.haidechizi.i18n.code.generator.common.message.config.GeneratorProperties;
import com.haidechizi.i18n.code.generator.common.message.utils.FileTypeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;

/**
 * key生成器适配
 */
public class KeyGeneratorAdapter implements KeyGenerator {

    private String defaultName = "default";

    @Autowired
    private GeneratorProperties configuration;

    @Override
    public String generatorKey(String data, String fileType, String content) {
        String name = defaultName;
        if (!StringUtils.isEmpty(configuration.getKeyGeneratorName())) {
            name = configuration.getKeyGeneratorName();
        }
        // 判断枚举类key生成规则
        if (configuration.isEnumKey() && FileTypeUtils.isEnum(fileType, content)) {
            name = "enum";
        }
        return KeyGeneratorFactory.getKeyGenerator(name).generatorKey(data, fileType, content);
    }

    /**
     * key generator 名称
     *
     * @return
     */
    @Override
    public String name() {
        return null;
    }
}
